
#include<iostream>

using namespace std;

//方向数组
int dx[8] = { -1,-1,-1,0,0,1,1,1 };
int dy[8] = { -1,0,1,-1,1,-1,0,1 };

int main()
{
    int n=3, m=3; cin >> n >> m;
   // n = 2, m = 3;  
    char a[n][m];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            cin >> a[i][j];

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)  
        {
            int count = 0;
            if (a[i][j] == '*')cout << "*";
            else
            {
                for (int k = 0; k < 8; k++)
                {
                    int x = i + dx[k], y = j + dy[k];
                    if (x >= 0 && x < n && y >= 0 && y < m && a[x][y] == '*')
                        count++;
                }
                cout << count;
            }

        }
        cout << endl;
    }

    return 0;
}
